package fs

import (
	"dfs/server/master/core"
	"strings"
)

var (
	fs     core.FileSystem
	inited = false
)

func Init() {
	fs.Init()
	inited = true
}

func Get(url string) (string, bool) {
	if !inited {
		Init()
	}
	node := fs.Get(url)
	if node.IsDir() {
		return "", false
	}
	return strings.Join(node.Blocks, ";"), true
}

func Put(url string, length int) (string, bool) {
	if !inited {
		Init()
	}
	blocks, ok := fs.Put(url, length)
	var res string
	if ok {
		res = strings.Join(blocks, ";")
	}
	return res, ok
}

func Mkdir(url string) bool {
	if !inited {
		Init()
	}
	return fs.Mkdir(url)
}

func Delete(url string) bool {
	if !inited {
		Init()
	}
	return fs.Delete(url)
}
